package net.imagine.provider.skyline;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;

import net.imagine.core.crop.ImageCropTask;

public class SkylineImageCropTask implements ImageCropTask {
	protected long albumId;
	protected long userId;
	protected Integer offsetX;
	protected Integer offsetY;
	protected Integer cropSize;
	protected Integer finalSize;
	protected boolean needResize = true;
	protected String remoteFileKey;
	protected String localStorePath;
	protected long fileSize;
	
	public SkylineImageCropTask(String remoteFileKey, int finalSize) {
		this.remoteFileKey = remoteFileKey;
		this.finalSize = finalSize;
	}

	public long getAlbumId() {
		return albumId;
	}

	public void setAlbumId(long albumId) {
		this.albumId = albumId;
	}

	public long getUserId() {
		return userId;
	}

	public void setUserId(long userId) {
		this.userId = userId;
	}

	public Integer getOffsetX() {
		return offsetX;
	}

	public void setOffsetX(Integer offsetX) {
		this.offsetX = offsetX;
	}

	public Integer getOffsetY() {
		return offsetY;
	}

	public void setOffsetY(Integer offsetY) {
		this.offsetY = offsetY;
	}

	public Integer getCropSize() {
		return cropSize;
	}

	public void setCropSize(Integer cropSize) {
		this.cropSize = cropSize;
	}

	public Integer getFinalSize() {
		return finalSize;
	}

	public void setFinalSize(Integer finalSize) {
		this.finalSize = finalSize;
	}

	public boolean isNeedResize() {
		return needResize;
	}

	public void setNeedResize(boolean needResize) {
		this.needResize = needResize;
	}

	public String getRemoteFileKey() {
		return remoteFileKey;
	}

	public void setRemoteFileKey(String remoteFileKey) {
		this.remoteFileKey = remoteFileKey;
	}

	public String getLocalStorePath() {
		return localStorePath;
	}

	public void setLocalStorePath(String localStorePath) {
		this.localStorePath = localStorePath;
	}

	public long getFileSize() {
		return fileSize;
	}

	public void setFileSize(long fileSize) {
		this.fileSize = fileSize;
	}

	@Override
	public byte[] getData() throws IOException {
		if(localStorePath == null) {
			return null;
		} else {
			File file = new File(localStorePath);
			return FileUtils.readFileToByteArray(file);
		}
	}

	@Override
	public String getFilename() {
		return FilenameUtils.getName(remoteFileKey);
	}

	@Override
	public InputStream getInputStream() throws IOException {
		if(localStorePath == null) {
			return null;
		} else {
			File file = new File(localStorePath);
			return FileUtils.openInputStream(file);
		}
	}

}
